﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FastData
{
    public class DataPageSource
    {
        private int _pageSize = 10;
        public DataSet dataSet;
        private int totalPageCount = 0;
        private DataColumn _columns;

        public DataTable this[int pageNum]
        {
            get
            {
                return dataSet.Tables[pageNum - 1];
            }
        }

        public DataColumnCollection Columns
        {
            get
            {
                return dataSet.Tables[0].Columns;
            }
        }

        public DataRowCollection Rows
        {
            get
            {
                if (dataSet.Tables[dataSet.Tables.Count - 1].Rows.Count < _pageSize)
                {
                    return dataSet.Tables[dataSet.Tables.Count - 1].Rows;
                }
                else
                {
                    DataTable dataTable = dataSet.Tables[0].Copy();
                    dataTable.Clear();
                    dataTable.TableName = $"Table_{dataSet.Tables.Count}";
                    dataSet.Tables.Add(dataTable);
                    return dataTable.Rows;
                }
            }
        }


        public int TotalPageCount
        {
            get
            {
                totalPageCount = dataSet.Tables.Count;
                return totalPageCount;
            }
            set
            {
                totalPageCount = value;
            }
        }

        public DataPageSource(int pageSize)
        {
            dataSet = new DataSet();
            dataSet.Tables.Add("Table_0");
            _pageSize = pageSize;
        }

        public DataPageSource(DataSet _dataSet)
        {
            dataSet = _dataSet;
            _pageSize = dataSet.Tables[0].Rows.Count;
        }
    }
}
